package com.RKB.web;

import com.RKB.pojo.AccuracyRate;
import com.RKB.api.AjaxResult;
import com.RKB.pojo.AccuracyRate_Composition;
import com.RKB.pojo.AnswerResult;
import com.RKB.pojo.AnswerResult_Composition;
import com.RKB.service.AnswerResultService;
import com.RKB.utils.AccuracyCalculation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin //允许跨域请求 springboot原生不支持跨域。
@RestController
public class AnswerResultController {
    @Autowired
    private AnswerResultService answerResultService;
    private AccuracyCalculation accuracyCalculation = new AccuracyCalculation();

    /**
     *
     * @param uid
     * @return
     */
    @RequestMapping("/findOneAccuracyRate")   //正确率的记录
    public AjaxResult<AccuracyRate> findOneAccuracyRate(String uid) {
        AjaxResult<AccuracyRate> result = new AjaxResult<>();

//        这个是去查询在user_analysis里的记录，这里面主要是保存的做的题与做错的题的数目
        AnswerResult answerResultServiceOne = answerResultService.findOne("root");
//这里利用工具类进行百分比处理
        AccuracyRate accuracyRate = accuracyCalculation.accurate(answerResultServiceOne);



//        System.out.println(accuracyRate);
//        System.out.println(DevelopmentAndDesign);
        result.setCode(200);
        result.setMsg("成功");
        result.setData(accuracyRate);
        return result;
    }

    @RequestMapping("/findOneAccuracyRate_Composition")   //生成计组正确率的记录
    public AjaxResult<AccuracyRate_Composition> findOneAccuracyRate_Composition(String uid) {
        AjaxResult<AccuracyRate_Composition> result = new AjaxResult<>();

//        这个是去查询在user_analysis里的记录，这里面主要是保存的做的题与做错的题的数目
        AnswerResult_Composition nums = answerResultService.findOne_Composition("root");
//这里利用工具类进行百分比处理
        AccuracyRate_Composition accuracyRate = accuracyCalculation.accurate_Composition(nums);



//        System.out.println(accuracyRate);
//        System.out.println(DevelopmentAndDesign);
        result.setCode(200);
        result.setMsg("成功");
        result.setData(accuracyRate);
        return result;
    }
}
